home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
s_to_z
/
vpe_130
/
delphi
/
vpedemo
/
unit1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-09-15
|
45KB
|
1,418 lines
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, VPENGINE, StdCtrls, Menus, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
GenerateData1: TMenuItem;
DeleteReport1: TMenuItem;
N1: TMenuItem;
Exit1: TMenuItem;
Demos1: TMenuItem;
CapabilitiesPrecision1: TMenuItem;
SpeedTables1: TMenuItem;
Colors1: TMenuItem;
Report1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
PrintinBackground1: TMenuItem;
CloseColors1: TMenuItem;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure CapabilitiesPrecision1Click(Sender: TObject);
procedure GenerateData1Click(Sender: TObject);
procedure DeleteReport1Click(Sender: TObject);
procedure SpeedTables1Click(Sender: TObject);
procedure Colors1Click(Sender: TObject);
procedure Report1Click(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure PrintinBackground1Click(Sender: TObject);
procedure CloseColors1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
private
{ Private declarations }
procedure AppOnMessage(var Msg: TMsg; var Handled: boolean);
procedure VPEHelp(var Msg: TMsg); message VPE_HELP; {VPE sends this message to the form, not the application}
procedure WMKeyDown(var Msg: TWMKeyDown); message WM_KEYDOWN;
public
{ Public declarations }
CanClose : byte;
DemoText : PChar;
PrecisionHDoc : longint;
PBackGndHDoc : longint;
ReportHDoc : longint;
ColorsHDoc : longint;
SpeedHDoc : longint;
procedure Precision(const Mode : integer);
procedure ReportTest;
procedure ColorTest;
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3;
{$R *.DFM}
function pow(x:double; n:byte):double;
var
m : byte;
f : double;
begin
try
m := n;
case m of
0 : f := 1.0;
1 : f := x;
else f := x * pow(x, m - 1);
end; { case }
if (n < 0) then
Result := 1.0 / f
else
Result := f;
except
on EZeroDivide do
Result := 0;
end;
end;
procedure MakeDemoText(ZString : PChar);
begin
StrCopy(ZString, 'The moment of impact bursts through the silence and in a roar of sound, the');
StrCat(ZString, 'final second is prolonged in a world of echoes as if concrete and clay of');
StrCat(ZString, 'Broadway itself was reliving its memories.' + #10);
StrCat(ZString, 'The last great march past. Newsman stands limp as a whimper as audience and');
StrCat(ZString, 'eventare locked as one. Bing Crosby coos''You don''t have to feel pain');
StrCat(ZString, 'to sing the blues, you don''t have to holla - you don''t feel a thing in your');
StrCat(ZString, 'dollar collar.'' Martin Luther cries ''Everybody Sing!'' and rings the grand old');
StrCat(ZString, 'liberty bell. Leary, weary of his prison cell, walks on heaven, talks on hell.' + #10);
StrCat(ZString, 'Who needs Medicare and the 35c flat rate fare, when Fred Astaire and');
StrCat(ZString, 'Ginger Rogers are dancing through the air? From Broadway Melody stereotypes');
StrCat(ZString, 'the band returns to ''Stars and Stripes'' bringing a tear to the moonshiner,');
StrCat(ZString, 'who''s been pouring out his spirit from the illegal still. The pawn broker');
StrCat(ZString, 'clears the noisy till and clutches his lucky dollar bill.' + #10);
StrCat(ZString, 'Then the blackout.' + #10 + #10);
StrCat(ZString, '(Genesis, ''The Lamb lies down on Broadway'')');
end;
{===Precision===}
const
HEADLINE = 1;
{Page 1 of Precision demo}
procedure page1(hdoc: longint);
var
Page1Text : PChar;
y : integer;
begin
Page1Text := StrAlloc(2048);
try
StrCopy(Page1Text, '[Center PenSize 3]This demo shows the capabilities and precision of VPE.'+#10);
StrCat(Page1Text, 'Print this page and compare not only the ');
StrCat(Page1Text, 'positions of the frames,'+#10+'but the positions of each letter that can be seen.'+#10);
StrCat(Page1Text, '(Switch the grid on.)'+#10);
StrCat(Page1Text, 'This is true WYSIWYG !!!'+#10+'(''What you see is what you get'')'+#10);
StrCat(Page1Text, 'Note, that the nearest result can be seen at a scaling of 1:1.'+#10);
StrCat(Page1Text, 'With every other scaling you get ''best results'' in comparison to execution speed.');
y := VpeWriteBox(hdoc, 575, 200, 1625, -1, Page1Text);
StrCopy(Page1Text, '[''Arial'' FontSize 14 Left Bold Italic Underline PenSize 0]');
StrCat(Page1Text, 'RIGHT ALIGNED, 0.25 cm blue frame, light-blue backgr., red bold text, Arial 9pt');
y := VpeWriteBox(hdoc, 100, y + 75, 2000, -1, Page1Text);
VpeStoreSet(hdoc, HEADLINE);
VpeSelectFont(hdoc, 'Arial', 9);
VpeSetPen(hdoc, 25, PS_SOLID, COLOR_BLUE);
VpeSetTextColor(hdoc, COLOR_LTRED);
VpeSetFontAttr(hdoc, ALIGN_RIGHT, 1, 0, 0);
VpeSetTransparentMode(hdoc, 0);
VpeSetBkgColor(hdoc, COLOR_CYAN);
{// y+30 because frame = 0.25cm --> frame drawn around center of coordinates}
{// we also want a little gap between the headline and the frame}
y := VpeWriteBox(hdoc, 150, y + 30, 1850, -1, Form1.DemoText);
VpeSetTransparentMode(hdoc, 1);
VpeUseSet(hdoc, HEADLINE);
y := VpeWrite(hdoc, 250, y + 75, 2000, -1, 'JUSTIFIED, no frame, Times New Roman 11pt');
VpeSelectFont(hdoc, 'Times New Roman', 11);
VpeSetFontAttr(hdoc, ALIGN_JUSTIFIED, 0, 0, 0);
y := VpeWriteBox(hdoc, 250, y + 20, 1550, -1, Form1.DemoText);
VpeUseSet(hdoc, HEADLINE);
y := VpeWriteBox(hdoc, 250, y + 75, 2000, -1, 'CENTERED, thin yellow frame, Times New Roman 11pt');
VpeSelectFont(hdoc, 'Times New Roman', 11);
VpeSetFontAttr(hdoc, ALIGN_CENTER, 0, 0, 0);
VpeSetPen(hdoc, 5, PS_SOLID, COLOR_LTYELLOW);
y := VpeWriteBox(hdoc, 150, y + 20, 1850, -1, Form1.DemoText);
finally
StrDispose(Page1Text);
end;
end;
{Page 2 of Precision demo}
procedure Page2(hdoc : longint);
const
xr : double = 6;
yr : double = 18;
index : integer = 0;
skip : integer = 0;
first : integer = 0;
xx : integer = 0;
oldy : integer = 0;
segments : integer = 0;
type
TPointArray = array[0..0] of TPoint;
TPointPtr = ^TPointArray;
var
y : integer;
x : double;
xstep : double;
s : array[0..159] of char;
p : longint;
points : TPointPtr;
begin
VpePageBreak(hdoc);
VpeUseSet(hdoc, HEADLINE);
y := VpeWriteBox(hdoc, 200, 200, 2000, -1, 'An example of drawing (better to turn the grid off here):');
VpeSetPen(hdoc, 8, PS_SOLID, COLOR_BLACK);
VpeBox(hdoc, 200, 300, 1700, 1800);
VpeSetPen(hdoc, 3, PS_SOLID, COLOR_BLACK);
xstep := xr / 750;
{ // The following graph is created with VpeAddPolyPoint() }
x := -xr;
skip := 0;
VpeSetPen(hdoc, 2, PS_SOLID, COLOR_BLUE);
p := VpePolyLine(hdoc, 0, 1500);
for xx := 200 to 1699 do
begin
y := trunc(1050 - (pow(x, 3) - 2*pow(x, 2) - 8*x) / ( yr / 750));
x := x+xstep;
if (y < 300) then
begin
y := 300;
skip := 1;
continue;
end
else if (y > 1800) then
begin
y := 1800;
skip := 1;
continue;
end;
if (skip = 1) then
begin
VpeAddPolyPoint(hdoc, p, -1, -1);
oldy := y;
skip := 2;
end
else
begin
if (skip = 2) then
begin
VpeAddPolyPoint(hdoc, p, xx-1, oldy);
skip := 0;
end;
VpeAddPolyPoint(hdoc, p, xx, y);
inc(segments);
end;
end;
{ // The following graph is created directly with VpePolyLine() }
{$R-} {Range checking off for dynamic array}
GetMem(points, 3 * 1500 * sizeof(TPoint));
try
x := -xr;
first := 1;
VpeSetPen(hdoc, 2, PS_SOLID, COLOR_LTRED);
index := 0;
for xx := 200 to 1699 do
begin
y := trunc(1050 - (3*pow(x, 2) - 4*x - 8) / ( yr / 750)